public class Demo10 {
    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread t1 = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                    synchronized (locker1) {
                        System.out.println("拿到锁1");


                        synchronized (locker2) {
                            System.out.println("拿到锁2");
                        }
                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread t2 = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                    synchronized (locker2) {
                        System.out.println("拿到锁2");


                        synchronized (locker1) {
                            System.out.println("拿到锁1");
                        }
                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t1.start();
        t2.start();
    }
}
